/**
 *  Copyright (C) 2010  Thomas Volk
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.googlecode.bookmarks.web.forms;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.googlecode.bookmarks.core.service.ResourceService;
import com.googlecode.bookmarks.web.pages.HomePage;

public class BookmarkForm extends Form {
	private URL url;
	private String title;
	@SpringBean
	private ResourceService resourceService;

	public BookmarkForm(String id) {
		super(id);
		PropertyModel<URL> urlModel = new PropertyModel<URL>(this, "url");
		try {
			urlModel.setObject(new URL("http://"));
		} catch (MalformedURLException e1) {
			throw new RuntimeException(e1);
		}
		UrlTextField urlField = new UrlTextField("url", urlModel);
		add(urlField.setRequired(true));
		add(new TextField<String>("title", new PropertyModel(this, "title"))
				.setRequired(true));
		add(new Button("save") {
			@Override
			public void onSubmit() {

			}
		});
		add(new Button("cancel") {
			@Override
			public void onSubmit() {
				setResponsePage(new HomePage());
			}
		}.setDefaultFormProcessing(false));
	}

	public URL getUrl() {
		return url;
	}

	public String getTitle() {
		return title;
	}

	public void setUrl(URL url) {
		this.url = url;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public ResourceService getResourceService() {
		return resourceService;
	}

}
